//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;

namespace OpenLS.Chart
{
    public abstract class Unit : IOfficeXmlSerializable
    {
        #region IOfficeXmlSerializable Members

        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            ReadXmlCore(context);
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            WriteXmlCore(context);
        }

        #endregion

        internal abstract void ReadXmlCore(ReadContext context);

        internal abstract void WriteXmlCore(WriteContext context);

        internal static Unit ReadOptionalFrom(ReadContext context)
        {
            switch (context.ReaderLocalName)
            {
                case "custUnit":
                    {
                        Unit result = new CustomUnit();
                        ((IOfficeXmlSerializable) result).ReadXml(context);
                        return result;
                    }

                case "builtInUnit":
                    {
                        Unit result = new BuiltInUnit();
                        ((IOfficeXmlSerializable) result).ReadXml(context);
                        return result;
                    }
                case null:
                    return null;
                default:
                    throw new NotSupportedException();
            }
        }


    }
}